Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: extend cri apis for get envs #2163

Merged
merged 1 commit into from
Aug 30, 2018

Conversation

starnop
Copy link
Contributor

@starnop starnop commented Aug 27, 2018

Signed-off-by: Starnop starnop@163.com

Ⅰ. Describe what this PR did

The CRI query container information interface adds the output of the environment variables, and returns the envs of the container in the ContainerStatus interface

Ⅱ. Does this pull request fix one issue?

None.

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Done.

Ⅳ. Describe how to verify it

  1. Synchronize changes to the proto file of cri-tools.
  2. Use command crictl inspect to view the container's environment variables.

Ⅴ. Special notes for reviews

None.

@starnop starnop force-pushed the cri-extend-env branch 5 times, most recently from 48a11a1 to a3d4b03 Compare August 27, 2018 07:40
@starnop starnop changed the title feature: extend cri apis for get envs [WIP] feature: extend cri apis for get envs Aug 27, 2018
@starnop starnop force-pushed the cri-extend-env branch 3 times, most recently from 96bd336 to 27df1ef Compare August 27, 2018 09:10
@starnop starnop changed the title [WIP] feature: extend cri apis for get envs feature: extend cri apis for get envs Aug 27, 2018
@codecov-io
Copy link

codecov-io commented Aug 27, 2018

Codecov Report

Merging #2163 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2163      +/-   ##
=========================================
- Coverage   64.44%   64.4%   -0.05%     
=========================================
  Files         209     209              
  Lines       16723   16735      +12     
=========================================
+ Hits        10777   10778       +1     
- Misses       4622    4630       +8     
- Partials     1324    1327       +3
Flag Coverage Δ
#criv1alpha1test 32.97% <0%> (+0.06%) ⬆️
#criv1alpha2test 33.39% <83.33%> (-0.18%) ⬇️
#integrationtest 39.36% <0%> (-0.02%) ⬇️
#unittest 23.96% <91.66%> (+0.05%) ⬆️
Impacted Files Coverage Δ
cri/v1alpha2/cri.go 63.44% <100%> (-0.27%) ⬇️
cri/v1alpha2/cri_utils.go 82.55% <100%> (+0.29%) ⬆️
cri/stream/httpstream/spdy/upgrade.go 54.28% <0%> (-5.72%) ⬇️
ctrd/image.go 75% <0%> (-3.95%) ⬇️
apis/server/utils.go 66.66% <0%> (+4.76%) ⬆️

@@ -774,6 +774,7 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt
Volumes: parseVolumesFromPouch(container.Config.Volumes),
Resources: parseResourcesFromPouch(resources, diskQuota),
QuotaId: container.Config.QuotaID,
Envs: parseEnvsFromPouch(container.Config.Env),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should add Pouch in the function naming. Please change a proper one. @starnop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@starnop Maybe we should rename the functions like parseEnvsFromPouch, parseResourcesFromPouch in another PR, they all do the same thing :)

@allencloud WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I will do that in the next pull request.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still insist that we could finish in the pull request. How about convertEnvsForCRI or convertContainerEnvForCRI?

for _, env := range pouchEnvs {
runtimeEnv := &runtime.KeyValue{}
if strings.Count(env, "=") == 1 {
envItem := strings.Split(env, "=")
Copy link
Collaborator

@allencloud allencloud Aug 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if env is equal to a=b=c? Do we need to cover this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allencloud Actually the envs here is returned from pouchd and they should have been validated when input to pouchd.

So maybe we don't need to check again here.

Copy link
Contributor Author

@starnop starnop Aug 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in fact, the case a=b=c will not be passed by pouchd.
Even if that happens, the upper level can also deal with it by key.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you are using envItem[1] to take b and ignoring =c, right? @starnop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a=b=c is valid because b=c is value.

# vagrant @ ubuntu-xenial in ~ [20:36:09]
$ A=1=2 echo ${A}
1=2

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sponsor @fuweid 's point of view. Your split way has potential risk. Do you agree? @starnop

@@ -1087,6 +1087,22 @@ func parseVolumesFromPouch(containerVolumes map[string]interface{}) map[string]*
return volumes
}

// parseEnvsFromPouch parse Envs from []string to []*runtime.KeyValue
func parseEnvsFromPouch(pouchEnvs []string) (criEnvs []*runtime.KeyValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are not parsing, you just did the translation thing.

fuweid
fuweid previously requested changes Aug 28, 2018
for _, env := range pouchEnvs {
runtimeEnv := &runtime.KeyValue{}
if strings.Count(env, "=") == 1 {
envItem := strings.Split(env, "=")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a=b=c is valid because b=c is value.

# vagrant @ ubuntu-xenial in ~ [20:36:09]
$ A=1=2 echo ${A}
1=2

@starnop
Copy link
Contributor Author

starnop commented Aug 29, 2018

@fuweid Done. :)

@starnop starnop force-pushed the cri-extend-env branch 4 times, most recently from 21296b8 to 27e88f2 Compare August 29, 2018 11:03
Signed-off-by: Starnop <starnop@163.com>
@allencloud
Copy link
Collaborator

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Aug 30, 2018
@allencloud allencloud merged commit c71d3ae into AliyunContainerService:master Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants